app.controller("menuCtrl", ["$scope", "$http", "$stateParams", function ($scope, $http, $stateParams) {
    $http.get("/menu_list").then(function (success) {
        $scope.menus = success.data;
    }, function (err) {})
}])
app.controller("main_index_table", ["$scope", "$http", "$state", "$stateParams", function ($scope, $http, $state, $stateParams) {
    //页面对象
    $scope.page = {
        titleData: [], //表格标题数组
        datas: [], //表格数据数组
        pages: [], //页码数组
        checkdata: [], //选中状态下的数据行ID
        pageselect: [2, 5, 10], //可选择每页显示条数数组
        active: 1, //当前页
        pagelist: 3, //每页显示数据条数
        pageTotal: 0, //总页数
        listTotal: 0, //总条数
        count: 5, //页码可显示数，即页码数组长度
    };
    //页码点击后请求函数
    $scope.page.click = function () {
        $http.post("/data_list", angular.toJson({
            page: {
                active: $scope.page.active,
                pagelist: $scope.page.pagelist
            },
            state: {
                id: $scope.stateID,
                ChildId: $scope.ChildId
            }
        })).then(function (success) {
            $scope.page.titleData = success.data.data_title;
            $scope.page.datas = success.data.lists;
            $scope.page.listTotal = success.data.listTotal;
            $scope.page.pageTotal = Math.ceil($scope.page.listTotal / $scope.page.pagelist);
            $scope.$broadcast("parentChange", {
                pageTotal: $scope.page.pageTotal,
                active: $scope.page.active,
                pages: $scope.page.pages,
                count: $scope.page.count
            });
        }, function (err) {

        })
    }
    var ChildHttp = function () {
        $http.post("/ChildMenu", {
            id: $scope.stateID
        }).then(function (success) {
            $scope.childMenus = success.data;
        }, function (err) {
            console.log(err);
        })
    }
    //判断页面显示
    var stateUpdateWatch = function () {
        if ($stateParams.mainID != "") {
            $scope.stateID = $stateParams.mainID;
            ChildHttp();
            if ($stateParams.ChildID != "") {
                $scope.ChildId = $stateParams.ChildID;
            } else {
                $scope.ChildId = "";
            }
            $scope.page.click();
        } else {
            $scope.stateID = "";
        }
    }
    stateUpdateWatch();
    //  //批量修改函数
    //  $scope.page.updateDatas=function(){
    //     var checkdata=$scope.page.checkdata;
    //     if(checkdata==""){
    //         alert("请批量选中需要修改的数据");
    //     }
    //     console.log($scope.page.checkdata)
    // }
    // //数据行修改函数
    // $scope.page.updateData=function(value){

    // }
}]);
app.controller("user_Index_Ctrl", ["$scope", "$http", "$location", function ($scope, $http, $location) {
    //初始化界面获取资料
    $scope.loginData = function () {
        $scope.indexData=true;
        $http.get("").then(function (success) {
            $scope.userData = success.data;
        }, function (err) {});
    };
    $scope.loginData();
    $scope.remove = function () {
        $scope.updateData = [];
        $scope.myForm.myName.$dirty = false;
        $scope.myForm.myEmail.$dirty = false;
        $scope.myForm.myNic.$dirty = false;
        $scope.myFormPass.myoldPass.$dirty = false;
        $scope.myFormPass.newPass.$dirty = false;
        $scope.myFormPass.mynewPass.$dirty = false;
    };
    //修改信息
    $scope.UpdateData = function () {
        $http.post("", $scope.updateUserData).then(function (success) {
            console.log(success.data.msg);
            $scope.upDate=!$scope.upDate;
            $scope.upDatePass=!$scope.upDatePass;
        }, function (err) {
            console.log(err)
        })
    }
}])